using SeataNet.Core.AT.UndoLog;
using System.Data.Common;

namespace SeataNet.Core.Database
{
    /// <summary>
    /// 数据库方言接口
    /// </summary>
    public interface IDatabaseDialect
    {
        /// <summary>
        /// 数据库类型
        /// </summary>
        DatabaseType DatabaseType { get; }

        /// <summary>
        /// 获取表元数据
        /// </summary>
        Task<TableMeta> GetTableMetaAsync(DbConnection connection, string tableName);

        /// <summary>
        /// 构建前镜像查询SQL
        /// </summary>
        string BuildBeforeImageSql(SqlRecognizeResult recognizeResult, TableMeta tableMeta);

        /// <summary>
        /// 构建后镜像查询SQL
        /// </summary>
        string BuildAfterImageSql(SqlRecognizeResult recognizeResult, TableMeta tableMeta);

        /// <summary>
        /// 获取SQL识别器
        /// </summary>
        ISqlRecognizer GetSqlRecognizer(string sql);
    }

    /// <summary>
    /// 数据库类型
    /// </summary>
    public enum DatabaseType
    {
        MySQL,
        PostgreSQL,
        SqlServer,
        Oracle,
        SQLite
    }
}
